<?php
$cur_dir = dirname(__FILE__);

$lib_dir = $cur_dir.'/lib/';
$required_files = array(
    "{$lib_dir}exceptions.inc",
	"{$lib_dir}config.inc",
	"{$lib_dir}db.inc",
	"{$lib_dir}base.inc",
	"{$lib_dir}session.inc",
	"{$lib_dir}user.inc",
    "{$lib_dir}codeversion.inc",
	"{$lib_dir}simple_html_dom.php"
);

foreach ($required_files as $file) {
	if (!include_once($file)) {
		echo "Could not load file '$file'";
		exit;
	}
}

// load settings
if (!include_once($cur_dir . '/settings/settings.inc')) {
	throw new Exception("Could not load the settings file.");
}

// load libs
$lib_files = array(
	"{$lib_dir}ablib.inc",
);

foreach ($lib_files as $file) {
	if (!include_once($file)) {
		echo "Could not load file '$file'. ";
		exit;
	}
}

// init db
setup_db_connections();

global $SESSION_STARTED;
if (!isset($SESSION_STARTED)) {
    $SESSION_STARTED = false;
}

if ($SESSION_STARTED === false) {
    // session
    session_start();
    $SESSION_STARTED = true;
}

